package com.hippomeetsskunk.savanna.types.world;

public class Time {

	private final static int DAYS_OF_YEAR = 360;
	private final static int DAYS_OF_MONTH = 30;
	private final static int DAYS_OF_WEEK = 7;
	
	public enum Season {
		Spring, Summer, Autumn, Winter
	}
	
	public enum Month {
		January, February, March, April, May, June, July, August, September, October, November, December
	}
	
	public enum Weekday {
		Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
	}
	
	private int day = 0;
	private int year = 1;

	public Time(){
	}
	
	public Time(int day, int year){
		this.day = day;
		this.year = year;
	}
	
	public int getDay(){
		return day;
	}
	
	public Weekday getWeekday(){
		int d = DAYS_OF_YEAR * (year - 1) + day - 1;
		return Weekday.values()[d % DAYS_OF_WEEK];
	}
	
	public Month getMonth(){
		return Month.values()[(int) (day-1) / DAYS_OF_MONTH];
	}
	
	public Season getSeason(){
		int month = (int) (day-1) / DAYS_OF_MONTH;
		month -= 2;
		if (month < 0) month += Month.values().length;
		month += 2;
		return Season.values()[month / 4];
	}
	
	public int getYear(){
		return year;
	}
	
	public int getDayOfMonth(){
		return (day-1) % DAYS_OF_MONTH + 1;
	}
	
	public void startDay(){
		++day;
		if (day > DAYS_OF_YEAR){
			day = 1;
			++year;
		}
	}

	public double getYearFraction() {
		return (day - 1.0) / DAYS_OF_YEAR;
	}

	@Override
	public String toString() {
		return "Time[" + getDayOfMonth() + ". " + getMonth() + " " + year + "]";
	}
	
	public int getTimeStamp(){
		return year * DAYS_OF_YEAR + day;
	}
}
